import { createApp } from 'vue'
import LoginPage from './components/LoginPage.vue'
import JDHomepage from './components/JDHomepage.vue'

// 简单的路由管理器
class Router {
  private currentComponent: any = null
  private app: any = null
  private container: HTMLElement

  constructor(container: HTMLElement) {
    this.container = container
  }

  // 初始化应用（默认显示登录页面）
  init() {
    this.app = createApp(LoginPage)
    this.currentComponent = LoginPage
    this.app.mount(this.container)
  }

  // 跳转到登录页面
  goToLogin() {
    if (this.currentComponent !== LoginPage) {
      this.app.unmount()
      this.app = createApp(LoginPage)
      this.currentComponent = LoginPage
      this.app.mount(this.container)
    }
  }

  // 跳转到首页
  goToHome() {
    if (this.currentComponent !== JDHomepage) {
      this.app.unmount()
      this.app = createApp(JDHomepage)
      this.currentComponent = JDHomepage
      this.app.mount(this.container)
    }
  }

  // 检查当前页面
  getCurrentPage() {
    return this.currentComponent
  }
}

export default Router 